import { queryPerson } from '@/utils/common';
import AdSelect from '@/components/AdSelect';
import AdSearch from '@/components/AdSearch';
import {
    formatPrice,
} from '@/utils/common';

export const formate = 'YYYY-MM-DD HH:mm:ss';
export const formateNOSecond = 'YYYY-MM-DD HH:mm';

export const codes = {
    page: 'INCIDENTALPAGE',
    select: 'MISCELLANEOUS_SELECT',
    showDetail: 'MISCELLANEOUS_VIEW',
    add: 'MISCELLANEOUS_ADD',
    bill: 'MISCELLANEOUS_GENERATEBILL',
    edit: 'MISCELLANEOUS_UPD',
    remove: 'MISCELLANEOUS_DEL',
    import: 'MISCELLANEOUS_GENERATEBILL'
};
// UNSEALED 草稿、 COMMIT 已提交、 CONFIRM 已确认
export const incidentalStatusList = [
    { code: 'UNSEALED', value: '草稿' },
    { code: 'CONFIRM', value: '已确认' },
    { code: 'COMMIT', value: '已提交' },
];

export const allUrl = {
    companyList: 'tms/tms-incidental/selectSpplierList_s',
    userList: 'tms/tms-bill/selectUserList_s', //未配权限
    supplierList: 'tms/tms-bill/selectSpplierList_s',//未配权限
    supplierDetail: 'mds/d-customer/viewCompany',
    userDetail: 'mds/mds-user/viewDetails',
};

export const routeUrl = {
    add: '/carAccount/IncidentalList/addIncidental',
    edit: '/carAccount/IncidentalList/editIncidental',
    billEdit: '/carAccount/billList/editBill',
};

export const allDispatchType = {
    list: 'incidental/selectIncidentalList',
    detail: 'incidental/selectIncidentalDetail',
    remove: 'incidental/removeIncidental',
    genBills: 'incidental/generatedBills',
    operate: 'incidental/incidentalOperate',

    value: 'incidental/allValus',
};

export function renderTableAdSelect({ key, data, value, props }) {
    let params = { onlyRead: true, value };
    if (key) {
        const { dictObject } = props;
        params = { data: dictObject[key], payload: { code: [key] }, ...params };
    } else {
        params = { data, ...params };
    }
    return <AdSelect {...params} />;
}

export function renderTableAdSearch({ value, props }) {
    if (!value || !searchValue) return '';
    const { searchValue } = props;
    const params = {
        onlyRead: true,
        value: searchValue[value],
        label: 'loginName',
        name: 'sysName',
    };
    return <AdSearch {...params} />;
}

export function selectIncidentalList({ payload = {}, props } = {}) {
    const { dispatch, searchValue } = props;
    dispatch({
        type: allDispatchType.list,
        payload,
        callback: data => {
            if (!data) return;
            queryPerson({ data, props: props, url: allUrl.userList });
        },
    });
}

export function selectIncidentalDetailAndInfo({ type, payload, props, callback }) {
    const { dispatch } = props;
    dispatch({
        type,
        payload,
        callback: data => {
            if (!data) return;
            callback && callback(data);
        },
    });
}

export function saveAllValues({ payload = {}, props } = {}) {
    const { dispatch } = props;
    dispatch({
        type: 'incidental/allValus',
        payload,
    });
}

export const columnInci = [
    {
        title: '单号',
        dataIndex: 'miscellaneousNo',
        key:'miscellaneousNo',
    },
    {
        title: '金额',
        dataIndex: 'fee',
        key:'fee',
        render: text => <span>{formatPrice(text)}</span>,
    },
]